load("@npm//scss-bundle:index.bzl", "scss_bundle")
load("//src/cdk:config.bzl", "CDK_SCSS_LIBS")
load(
    "//src/material:config.bzl",
    "MATERIAL_ENTRYPOINTS",
    "MATERIAL_SCSS_LIBS",
    "MATERIAL_TARGETS",
    "MATERIAL_TESTING_TARGETS",
)
load("//tools:defaults.bzl", "ng_package", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
    name = "material",
    srcs = ["index.ts"],
    module_name = "@angular/material",
)

filegroup(
    name = "overviews",
    srcs = ["//src/material/%s:overview" % name for name in MATERIAL_ENTRYPOINTS],
)

scss_bundle(
    name = "theming_bundle",
    outs = ["_theming.scss"],
    args = [
        "--entryFile=$(execpath :theming-bundle.scss)",
        "--outFile=$(execpath :_theming.scss)",

        # The config file has to be passed in explicitly, otherwise the
        # bundler will still run, but produce massive bundle files.
        "--config=scss-bundle.config.json",
    ],
    data = CDK_SCSS_LIBS + MATERIAL_SCSS_LIBS + [
        "theming-bundle.scss",
        "//src/material/core:theming_scss_lib",
        # Config file is required by "scss-bundle" and will be automatically
        # loaded by the CLI. It expects the config to be in the execroot.
        "//:scss-bundle.config.json",
    ],
)

# Creates the @angular/material package published to npm.
ng_package(
    name = "npm_package",
    srcs = [
        "package.json",
    ],
    data = [
        ":theming_bundle",
        "//src/material/core:theming_scss_lib",
        "//src/material/prebuilt-themes:deeppurple-amber",
        "//src/material/prebuilt-themes:indigo-pink",
        "//src/material/prebuilt-themes:pink-bluegrey",
        "//src/material/prebuilt-themes:purple-green",
    ] + MATERIAL_SCSS_LIBS,
    entry_point = ":index.ts",
    entry_point_name = "material",
    nested_packages = ["//src/material/schematics:npm_package"],
    tags = ["release-package"],
    deps = MATERIAL_TARGETS + MATERIAL_TESTING_TARGETS,
)
